import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
import sys


# -------- Step 1: Load data --------
# Replace with your actual filename


if (len(sys.argv) > 1):
    filename = sys.argv[1]
else:
    filename = "curvas.csv"

# Assumes no header row; each row = one simulation run; 240 columns
df = pd.read_csv(filename, header=None)
print("Data shape:", df.shape)   # should be (N_runs, 240)

data = df.values   # shape (N_runs, 240)

# -------- Step 2: Compute mean & std --------
mean_curve = np.mean(data, axis=0)   # length = 240
std_curve  = np.std(data, axis=0)    # length = 240

# -------- Step 3: Prepare time axis --------
n_steps = mean_curve.shape[0]
time = np.arange(n_steps)   # e.g., 0,1,2,…,239
# If each step represents “1 day” you can label accordingly
days = time   # same units

# -------- Step 4: Plotting --------
fig, ax = plt.subplots(figsize=(10,6))

# Plot mean
ax.plot(days, mean_curve, color='blue', label='Mean curve')

# Plot variation band (mean ± std)
ax.fill_between(days,
                mean_curve - std_curve,
                mean_curve + std_curve,
                color='blue', alpha=0.2,
                label='± 1 standard deviation')

# Axis labels & title
ax.set_xlabel("Day")
ax.set_ylabel("Value (epidemic quantity)")
ax.set_title("Monte Carlo simulation: mean trajectory + variation")

# Set tick interval every 20 days (or adjust)
tick_interval = 20
ax.xaxis.set_major_locator(ticker.MultipleLocator(tick_interval))
ax.xaxis.set_minor_locator(ticker.MultipleLocator(tick_interval//2))
# Optionally rotate tick labels (if needed)
plt.xticks(rotation=0)

ax.grid(True, which='both', linestyle='--', alpha=0.5)
ax.legend()

plt.tight_layout()
plt.show()

